package cn.lnl.springcloud.service.impl;

import cn.lnl.springcloud.dao.PaymentDao;
import cn.lnl.springcloud.entities.Payment;
import cn.lnl.springcloud.service.PaymentService;
import cn.lnl.springcloud.utils.RedisLock;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author LNL
 * @date 2021/7/13 23:09
 */
@Service("paymentService")
public class PaymentServiceImpl implements PaymentService {

    @Resource
    private PaymentDao paymentDao;


    @Override
    public int create(Payment payment) {
        int count = 0;
        RedisLock lock = RedisLock.createLock(UUID.randomUUID().toString().replaceAll("-", ""));
        try {
            if (lock.lock()) {
                count = paymentDao.create(payment);
            }
        } catch (Exception e) {

        } finally {
            lock.unLock();
        }
        return count;
    }

    @Override
    public Payment getPaymentById(Long id) {
        return paymentDao.getPaymentById(id);
    }
}
